<template>
  <el-container>
    <el-header>
      <div class="logo"></div>
      <div class="title">外卖后台管理系统</div>
      <div class="operation">
        <el-dropdown trigger="click" @command="handleCommand">
          <span class="el-dropdown-link">
            <img src="@/assets/imgs/avater.png" alt="" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-user" command="user"
              >个人中心</el-dropdown-item
            >
            <el-dropdown-item icon="el-icon-share" command="xxlt"
              >学术论坛</el-dropdown-item
            >
            <el-dropdown-item icon="el-icon-switch-button" command="logout"
              >退出登录</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '60px' : '200px'">
        <!-- 折叠的div -->
        <div class="collapse" @click="doCollapse">l l l</div>
        <!-- 侧边栏 -->
        <el-menu
          default-active="2"
          class="el-menu-vertical-demo"
          @open="handleOpen"
          @close="handleClose"
          :collapse="isCollapse"
          :collapse-transition="false"
          background-color="#272c33"
          text-color="#FFFFFF"
          unique-opened
          :router="true"
        >
          <MenuTree :menuList="menuList"></MenuTree>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//1.导入组件
import MenuTree from "../../components/Menu/MenuTree.vue";
import { tree } from "../../api/menu";
export default {
  data() {
    return {
      isCollapse: false,
      menuList: [],
    };
  },
  //2.注册组件
  components: {
    MenuTree,
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    //获取菜单树
    async getMenuTree() {
      let result = await tree();
      this.menuList = result.data.tree;
    },
    //折叠缩放
    doCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    handleCommand(command) {
      if (command === "logout") {
        //清空vuex记忆本地存储等内容

        //跳转登录页面
        this.$router.push("/login");
      }
    },
  },
  //窗体加载事件
  created() {
    this.getMenuTree();
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100%;
}

.el-header {
  background-color: #272c33;

  display: flex;
  //对齐方式为左中右对齐
  justify-content: space-between;
  align-items: center;

  img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }

  .title {
    color: #ffffff;
    font-size: 25px;
    font-weight: bold;
  }
}

.el-aside {
  background-color: #272c33;

  .el-menu {
    border-right: 0;
  }

  .collapse {
    width: 100%;
    height: 30px;
    background-color: #2d3a4b;
    text-align: center;
    line-height: 30px;
    font-size: 25px;
  }
}

.el-main {
  background-color: #ffffff;
}
.el-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #272c33;
  padding: 0 40px 0 40px;
  img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
  }
  .title {
    font-size: 24px;
    font-weight: 400;
    color: #ffffff;
    font-family: "正楷";
  }
}

.el-aside {
  .el-menu {
    border-right: none;
  }
  background-color: #272c33;
  .collapse {
    text-align: center;
    color: rgb(255, 255, 255);
    background-color: #2d3a4b !important;
    cursor: pointer;
  }
}
</style>